package pl.edu.agh.neuraleconomy.core.nn.transformer;

import java.util.Arrays;

import pl.edu.agh.neuraleconomy.core.ta.indicator.ROCCalculator;

public class ROCDataTransformer extends IndicatorTransformer<ROCCalculator> {

	protected int period;

	public ROCDataTransformer(int period) {
		super(new ROCCalculator(period));
		this.period = period;
	}

	public double[] revert(double[] originHead, double[] transformed, boolean includeHead) {
		double[] resWithHead = Arrays.copyOf(originHead, originHead.length + transformed.length);
		double[] res = new double[transformed.length];

		for (int i = 0; i < transformed.length; i++) {
			double nextValue = getNextRevertedValue(resWithHead[originHead.length + i - period], transformed[i]);
			resWithHead[originHead.length + i] = nextValue;
			res[i] = nextValue;
		}

		return includeHead ? resWithHead : res;
	}

	private double getNextRevertedValue(double origin, double roc) {
		return (1 + roc) * origin;
	}

	public int getInputLenForOutputLen(int inputLen) {
		return inputLen + period;
	}

}
